const axios = require('axios');
const MockAdapter = require('axios-mock-adapter');
const normalAxios = axios.create();
const mockAxios = axios.create();
import Config from "./config";
import {jsonToTreeJson} from "../utils";
import reqTools from "../utils/reqTools";

// mock 数据
var mock = new MockAdapter(mockAxios);

mock.onGet('/getMenu').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/sysMenu',...config.params,).then((res) => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
mock.onPost('/addMenu').reply((config) => {
  return new Promise(function(resolve, reject) { 
     reqTools.post('/api/sysMenu', config.data).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
mock.onDelete('/delMenu').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.delete( '/api/sysMenu/'+config.id).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});
mock.onPut('/updateMenu').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.put( '/api/sysMenu',config.data,
     ).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});


export default mockAxios;
